using System.Collections.Generic;
using LitJson2;
using UnityEngine;

/****************************************************
// 功能：接收IOS、Android向Unity发送消息的类
// | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
// | Copyright (c) 2021-2025 聊来 All rights reserved.
// | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">聊来</a> )
// | @Author: 贯彻己道的云 <18970881148@qq.com>
// | DateTime: 2025/1/7 10:29:54
*****************************************************/


public class PlatformScript : MonoBehaviour
{
    private struct PlatformMsg
    {
        public int iMsgId;
        public int iParam1;
        public int iParam2;
        public int iParam3;
        public string strParam1;
        public string strParam2;
        public string strParam3;
    }

    private readonly Queue<PlatformMsg> msgQueue = new Queue<PlatformMsg>();

    protected void OnMessage(string param)
    {
        JsonData json = JsonMapper.ToObject(param);
        PlatformMsg msg;
        msg.iMsgId = (int) json["iMsgId"];
        msg.iParam1 = (int) json["iParam1"];
        msg.iParam2 = (int) json["iParam2"];
        msg.iParam3 = (int) json["iParam3"];
        msg.strParam1 = (string) json["strParam1"];
        msg.strParam2 = (string) json["strParam2"];
        msg.strParam3 = (string) json["strParam3"];
        
        msgQueue.Enqueue(msg);
    }

    private void Update()
    {
        while (msgQueue.Count > 0)
        {
            PlatformMsg msg = new PlatformMsg();
            JsonData json = JsonMapper.ToObject(msg.strParam1);
            switch (msg.iMsgId)
            {
                case Constants.PLATFORM_MSG_QQ_LOGIN_CALLBACK:
                    PhoneController.Instance.LoginCallBack(json, PlatformEnum.QQ, msg.iParam1);
                    break;
                case Constants.PLATFORM_MSG_WX_LOGIN_CALLBACK:
                    PhoneController.Instance.LoginCallBack(json, PlatformEnum.WX, msg.iParam1);
                    break;
                default:
                    break;
            }
        }
    }
}
